//
// Created by Mio on 24-12-27.
//

#ifndef AUDIOCAPTURE_H
#define AUDIOCAPTURE_H
#include "commonlooper.h"


class AudioCapture : public CommonLooper
{
public:
    AudioCapture();
    virtual ~AudioCapture();

    RET_CODE Init(const Properties& props);

    void Loop() override;

    void setCallback(CAPTURECALLBACK cb) { callback_ = cb; }


private:
    int openPcmFile(const char* filename);
    int readPcmFile(uint8_t* buf, int32_t size);
    int closePcmFile();
    std::string pcmInName_;
    FILE* pcmfd_ = nullptr;
    CAPTURECALLBACK callback_;
    uint8_t* pcmBuf_;
    int32_t pcmBufSize_;
    bool is_first_frame_;
    const int PCM_BUF_MAX_SIZE = 32768;

private:
    int audio_test_ = 0;
    int sample_rate_ = 48000;
};



#endif //AUDIOCAPTURE_H
